﻿<template>
  <div class="table">
    <!--表2季度生产情况T_MulQuartProduc-->
    <div class="divSearch">
      <Row>
        <Col span="24" class="col-margin"> 填报年度：
        <Select v-model="searchModel.FillInYear" placeholder="全部" style="width: 100px" @on-change="GetData()">
          <Option value="">全部</Option>
          <Option :value="item.DictText" v-for="item in CreateYearList" :key="item.DictValue">{{item.DictText}}</Option>
        </Select>
        <Button icon="ios-search" type="ghost" @click="GetData()" class="ButtonStyle">查询</Button>
        <Button icon="ios-download" type="primary" @click="ExcelDown()" class="searchButton" style="float:right;width: 100px;">数据导出</Button>
        <Upload :on-success="handleSuccess" :action="GetPostUrl()" style="float:right;width: 100px;" v-show="dataModel.ReportStatus <3">
          <Button type="primary" icon="ios-cloud-upload-outline" class="searchButton">数据导入</Button>
        </Upload>
        <Button icon="ios-cloud-download" type="primary" @click="TmpDown()" class="searchButton" style="width: 100px;">模板下载</Button>
        <!-- <label style="float:right;padding: 6px;font-size:16px;">当前状态:
          <span v-if="dataModel.ReportStatus==0" class="Error"></span> 
          <span v-else-if="dataModel.ReportStatus==1" class="NoReport">未填写</span>
          <span v-else-if="dataModel.ReportStatus==2" class="AlreadyReport">已填写</span>
          <span v-else-if="dataModel.ReportStatus==3" class="UpReport">已上报</span>
          <span v-else-if="dataModel.ReportStatus==4" class="Success">审核通过</span>               
      </label> -->
        </Col>
      </Row>
    </div>
      <Row>
        <Col>
        <Form ref="dataModel" :model="dataModel" :rules="ruleModel">
          <table class="reptable">
            <caption>
                <label style="float:left">{{searchModel.FillInYear}}表5蚕桑综合利用情况调查表</label>
                <label style="float:right">当前状态:
                  <Poptip trigger="hover" placement="left-start" v-model="visible" :content="ReportOpinion" v-if="dataModel.ReportStatus==0">
                      <span  class="Error">重新填写</span> 
                    </Poptip>
                  <!-- <span v-if="dataModel.ReportStatus==0" class="Error">重新填写</span>  -->
                  <span v-else-if="dataModel.ReportStatus==1" class="NoReport">未填写</span>
                  <span v-else-if="dataModel.ReportStatus==2" class="AlreadyReport">已填写</span>
                  <span v-else-if="dataModel.ReportStatus==3" class="UpReport">已上报</span>
                  <span v-else-if="dataModel.ReportStatus==4" class="Success">审核通过</span>  
                  <span v-else class="NoReport">无需填报</span>                  
                </label><br/>
            </caption>
          </table>
          <div>
            <table class="reptable" >
              <thead>
                <tr>
                  <th colspan="2">桑枝菌</th>
                  <th colspan="2">桑叶茶、菜</th>
                  <th colspan="2">桑果、汁、酒</th>
                  <th colspan="2">蚕沙提取叶绿素</th>
                  <th colspan="2">蚕沙肥料</th>
                  <th colspan="2">食用蛹、蛾</th>
                  <th colspan="2">蚕蛾酒</th>
                  <th colspan="2">其它</th>
                </tr>
                <tr>
                  <th>重量<br/>(吨)</th>
                  <th>产值<br/>(万元)</th>
                  <th>重量<br/>(吨)</th>
                  <th>产值<br/>(万元)</th>
                  <th>重量<br/>(吨)</th>
                  <th>产值<br/>(万元)</th>
                  <th>重量<br/>(吨)</th>
                  <th>产值<br/>(万元)</th>
                  <th>重量<br/>(吨)</th>
                  <th>产值<br/>(万元)</th>
                  <th>重量<br/>(吨)</th>
                  <th>产值<br/>(万元)</th>
                  <th>重量<br/>(吨)</th>
                  <th>产值<br/>(万元)</th>
                  <th>重量<br/>(吨)</th>
                  <th>产值<br/>(万元)</th>
                </tr>
              </thead>
              <tbody>
                <tr>
                  <td>
                    <Input style="display:none;" v-model="dataModel.Id"></Input>
                    <Input style="display:none;" v-model="dataModel.ReportId"></Input>
                    <Poptip trigger="focus" title="上年数据" :content="dataModel.OldMulFunWeight" placement="bottom">
                      <Form-item prop="MulFunWeight">
                        <Input v-model="dataModel.MulFunWeight"></Input>
                      </Form-item>
                    </Poptip>
                  </td>
                  <td>
                    <Poptip trigger="focus" title="上年数据" :content="dataModel.OldMulFunValue" placement="bottom">
                      <Form-item prop="MulFunValue">
                        <Input v-model="dataModel.MulFunValue"></Input>
                      </Form-item>
                    </Poptip>
                  </td>
                  <td>
                    <Poptip trigger="focus" title="上年数据" :content="dataModel.OldMulTeaWeight" placement="bottom">
                      <Form-item prop="MulTeaWeight">
                        <Input v-model="dataModel.MulTeaWeight"></Input>
                      </Form-item>
                    </Poptip>
                  </td>
                  <td>
                    <Poptip trigger="focus" title="上年数据" :content="dataModel.OldMulTeaValue" placement="bottom">
                      <Form-item prop="MulTeaValue">
                        <Input v-model="dataModel.MulTeaValue"></Input>
                      </Form-item>
                    </Poptip>
                  </td>
                  <td>
                    <Poptip trigger="focus" title="上年数据" :content="dataModel.OldMulFruitWeight" placement="bottom">
                      <Form-item prop="MulFruitWeight">
                        <Input v-model="dataModel.MulFruitWeight"></Input>
                      </Form-item>
                    </Poptip>
                  </td>
                  <td>
                    <Poptip trigger="focus" title="上年数据" :content="dataModel.OldMulFruitValue" placement="bottom">
                      <Form-item prop="MulFruitValue">
                        <Input v-model="dataModel.MulFruitValue"></Input>
                      </Form-item>
                    </Poptip>
                  </td>
                  <td>
                    <Poptip trigger="focus" title="上年数据" :content="dataModel.OldMulExcreWeight" placement="bottom">
                      <Form-item prop="MulExcreWeight">
                        <Input v-model="dataModel.MulExcreWeight"></Input>
                      </Form-item>
                    </Poptip>
                  </td>
                  <td>
                    <Poptip trigger="focus" title="上年数据" :content="dataModel.OldMulExcreValue" placement="bottom">
                      <Form-item prop="MulExcreValue">
                        <Input v-model="dataModel.MulExcreValue"></Input>
                      </Form-item>
                    </Poptip>
                  </td>
                  <td>
                    <Poptip trigger="focus" title="上年数据" :content="dataModel.OldMulFertWeight" placement="bottom">
                      <Form-item prop="MulFertWeight">
                        <Input v-model="dataModel.MulFertWeight"></Input>
                      </Form-item>
                    </Poptip>
                  </td>
                  <td>
                    <Poptip trigger="focus" title="上年数据" :content="dataModel.OldMulFertValue" placement="bottom"> 
                      <Form-item prop="MulFertValue">
                        <Input v-model="dataModel.MulFertValue"></Input>
                      </Form-item>
                    </Poptip>
                  </td>
                  <td>
                    <Poptip trigger="focus" title="上年数据" :content="dataModel.OldMulPupaeWeight" placement="bottom">
                      <Form-item prop="MulPupaeWeight">
                        <Input v-model="dataModel.MulPupaeWeight"></Input>
                      </Form-item>
                    </Poptip>
                  </td>
                  <td>
                    <Poptip trigger="focus" title="上年数据" :content="dataModel.OldMulPupaeValue" placement="bottom">
                      <Form-item prop="MulPupaeValue">
                        <Input v-model="dataModel.MulPupaeValue"></Input>
                      </Form-item>
                    </Poptip>
                  </td>
                  <td>
                    <Poptip trigger="focus" title="上年数据" :content="dataModel.OldMulWineWeight" placement="bottom">
                      <Form-item prop="MulWineWeight">
                        <Input v-model="dataModel.MulWineWeight"></Input>
                      </Form-item>
                    </Poptip>
                  </td>
                  <td>
                    <Poptip trigger="focus" title="上年数据" :content="dataModel.OldMulWineValue" placement="bottom">
                      <Form-item prop="MulWineValue">
                        <Input v-model="dataModel.MulWineValue"></Input>
                      </Form-item>
                    </Poptip>
                  </td>
                  <td>
                    <Poptip trigger="focus" title="上年数据" :content="dataModel.OldOtherWeight" placement="bottom">
                      <Form-item prop="OtherWeight">
                        <Input v-model="dataModel.OtherWeight"></Input>
                      </Form-item>
                    </Poptip>
                  </td>
                  <td>
                    <Poptip trigger="focus" title="上年数据" :content="dataModel.OldOtherValue" placement="bottom">
                      <Form-item prop="OtherValue">
                        <Input v-model="dataModel.OtherValue"></Input>
                      </Form-item>
                    </Poptip>
                  </td>
                </tr>
              </tbody>
            </table>
          </div>
        </Form>
        <div class="divButton">
          <Button type="primary" @click="save('dataModel')" :disabled="dataModel.ReportStatus < 3 && BtnSaveStatus ? false:true">保存</Button>
          <Button type="primary" @click="DataUp()" :disabled="dataModel.ReportStatus == 2 ? false:true">上报</Button>
        </div>
        <Alert banner type="error">
          <p style="color:red;">填报说明:</p>
          <p>若没有表格中的利用情况，请在对应位置填0；有表格中未统计的利用情况，可在“其他”一列中填入；</p>
          <p style="color:red;font-size: 16px;padding-top: 10px;">特别注意：若指标项没有数据，请直接填“0”</p>
          <span slot="desc"></span>
        </Alert>
        </Col>
      </Row>
  </div>
</template>
<script>
  export default {
    data() {
      const validateData = (rule, value, callback) => {
        var reg = /\S/;
        var temp = /^[0-9]\d*(\.\d+)?$/;//数字验证
        var p=/^[0-9]+([.]{1}[0-9]{1})?$/;//匹配整数或带一个小数
        if (reg.test(value)) {
          if (temp.test(value) == false) 
          {
            callback(new Error("必须是大于等于0的数字"));
          }
          else {
            if(p.test(value)==false)
            {
              callback(new Error("只能保留一位小数"));
            }
            else{
              callback();
            }
          }
        } 
        else {
          callback(new Error("不能为空"));
        }
      };
      return {
        ReportOpinion:'',
        visible:true,
        datas: {}, //table数据对象
        CreateYearList: this.GetGroupDict("ReportYear"), //上报年份
        CurrentYear: this.GetCurrentYear(), //当前年度
        BtnSaveStatus: false, //保存按钮开关
        //查询模型：根据需求删除不不要查询条件
        searchModel: {
          ReportCode: 'MulComplexQuest',
          FillInYear: '',
          TimesType: '',
          AreaCode: this.GetlocaStorage("CSuserinfo").AreaCode,
        },
        dataModel: { //编辑模型
          ReportCode: 'MulComplexQuest',
          FillInYear: '',
          TimesType: '',
          AreaCode: this.GetlocaStorage("CSuserinfo").AreaCode,
          Id: 0,
          ReportId: '',
          MulFunWeight: '',
          MulFunValue: '',
          MulTeaWeight: '',
          MulTeaValue: '',
          MulFruitWeight: '',
          MulFruitValue: '',
          MulExcreWeight: '',
          MulExcreValue: '',
          MulFertWeight: '',
          MulFertValue: '',
          MulPupaeWeight: '',
          MulPupaeValue: '',
          MulWineWeight: '',
          MulWineValue: '',
          OtherWeight: '',
          OtherValue: '',
          OldId: 0,
          OldReportId: '',
          OldMulFunWeight: '',
          OldMulFunValue: '',
          OldMulTeaWeight: '',
          OldMulTeaValue: '',
          OldMulFruitWeight: '',
          OldMulFruitValue: '',
          OldMulExcreWeight: '',
          OldMulExcreValue: '',
          OldMulFertWeight: '',
          OldMulFertValue: '',
          OldMulPupaeWeight: '',
          OldMulPupaeValue: '',
          OldMulWineWeight: '',
          OldMulWineValue: '',
          OldOtherWeight: '',
          OldOtherValue: '',
        },
        ruleModel: {
          MulFunWeight: [{
            validator: validateData,
            trigger: 'blur'
          }],
          MulFunValue: [{
            validator: validateData,
            trigger: 'blur'
          }],
          MulTeaWeight: [{
            validator: validateData,
            trigger: 'blur'
          }],
          MulTeaValue: [{
            validator: validateData,
            trigger: 'blur'
          }],
          MulFruitWeight: [{
            validator: validateData,
            trigger: 'blur'
          }],
          MulFruitValue: [{
            validator: validateData,
            trigger: 'blur'
          }],
          MulExcreWeight: [{
            validator: validateData,
            trigger: 'blur'
          }],
          MulExcreValue: [{
            validator: validateData,
            trigger: 'blur'
          }],
          MulFertWeight: [{
            validator: validateData,
            trigger: 'blur'
          }],
          MulFertValue: [{
            validator: validateData,
            trigger: 'blur'
          }],
          MulPupaeWeight: [{
            validator: validateData,
            trigger: 'blur'
          }],
          MulPupaeValue: [{
            validator: validateData,
            trigger: 'blur'
          }],
          MulWineWeight: [{
            validator: validateData,
            trigger: 'blur'
          }],
          MulWineValue: [{
            validator: validateData,
            trigger: 'blur'
          }],
          OtherWeight: [{
            validator: validateData,
            trigger: 'blur'
          }],
          OtherValue: [{
            validator: validateData,
            trigger: 'blur'
          }]
        },
        clientHeight: window.innerHeight - 260, //表格默认高度
      }
    },
    mounted() {
      //table高度计算方法
      const that = this;
      window.onresize = () => {
        return (() => {
          that.clientHeight = window.innerHeight - 260;
        })()
      };
    },
    methods: {
      //获取今往年数据
      GetData: function () {
        var self = this;
        var model = new Object();
        model.ReportCode = self.searchModel.ReportCode;
        if (self.searchModel.FillInYear != null && self.searchModel.FillInYear != '') {
          model.FillInYear = self.searchModel.FillInYear;
        } else {
          model.FillInYear = self.CurrentYear + '年'; //填报年度-----数据字典值
          self.searchModel.FillInYear = self.CurrentYear + '年';
        }
        model.AreaCode = self.searchModel.AreaCode;
        self.dataModel = {}; //清空当前数据            
        self.$http.post("Report/PostData", model).then( //获取数据编辑项的值
          function (res) {
            if (res.data.list.status == 2 || res.data.list.status == 1) {
              self.ReportOpinion=res.data.Opinion;
              self.dataModel = res.data.list.model;
              self.BtnSaveStatus = true;
            } else {
              self.dataModel = res.data.list.model;
              self.$Modal.warning({
                title: "提示信息",
                content: res.data.list.message
              });
              self.BtnSaveStatus = false;
            }
          }
        );
      },
      checkEmpty(value){
        if(value != null&& value!=""&&value!=" "){
            return true;
        }else{
            return false;
        }
      },
      //保存方法
      save(name) {
        var self = this;
        self.$refs[name].validate((valid) => {
          if (valid) {
            self.$http.put('MulComplexQuest', self.dataModel).then(
            function (res) {
              if (res.data.status == 1) {
                self.GetData();
                self.$Notice.success({
                  title: '数据保存成功！',
                  desc: false
                });
              } else {
                self.$Modal.warning({
                  title: "提示信息",
                  content: "更新失败,请与管理员联系!"
                });
              }
            });
          }
          else{
            this.$Notice.error({
                    title: '数据验证出错,请根据提示操作后再试!',
                    desc: '',
                });
            }
        });
      },
      //数据上报
      DataUp() {
        var self = this;
        self.$Modal.confirm({
          title: '提示信息',
          content: '<p>数据上报后，不能再更改，是否继续上报？</p>',
          onOk: () => {
            var model = new Object();
            model.Id = self.dataModel.ReportId;
            model.reportType = '3';
            model.strMsg = '';
            this.$http.post("Report/PostUpStatus", model).then(
              function (res) {
                if (res.data.status == 1) {
                  self.$Notice.success({
                    title: '数据上报成功！',
                    desc: false
                  });
                  self.GetData();
                } else {
                  self.$Modal.error({
                    title: "提示信息",
                    content: "数据上报失败!"
                  });
                }
              }
            );
          }
        });
      },
      //导入
      GetPostUrl() {
        var url = this.$http.defaults.baseURL + "Report/PostImportData?FillInYear="+this.searchModel.FillInYear+"&&ReportCode=" + this.searchModel.ReportCode +
          "&&AreaCode=" + this.searchModel.AreaCode;
        return url;
      },
      handleSuccess(res, file) {
        var self = this;
        self.GetData();
        self.$Notice.success({
          title: '数据导入成功！',
          desc: false
        });
      },
      //导出
      ExcelDown: function () {
        var self = this;
        var model = new Object();
        model.ReportCode = self.searchModel.ReportCode;
        if (self.searchModel.FillInYear != null && self.searchModel.FillInYear != '') {
          model.FillInYear = self.searchModel.FillInYear;
        } else {
          model.FillInYear = self.CurrentYear + '年'; //填报年度-----数据字典值
          self.searchModel.FillInYear = self.CurrentYear + '年';
        }
        model.AreaCode = self.searchModel.AreaCode;
        window.open(this.$http.defaults.baseURL + "MulComplexQuest/GetExcelData?ReportCode=" + model.ReportCode +
          "&&FillInYear=" + model.FillInYear + "&&AreaCode=" + model.AreaCode);
      },
      //模板下载
      TmpDown: function () {
        window.open(this.$http.defaults.baseURL + "Report/GetTemplateData?ReportCode=" + this.searchModel.ReportCode);
      },
    },
    //创建Vue页面方法
    created: function () {
      //创业Vue前调用获取this.datas: {},//table数据对象
      this.GetData();
    },
    watch: {
      //需要监听的在此处新增监听对象
    }
  }

</script>
